package April._23.work6;

import java.util.concurrent.ForkJoinPool;

//一堆垃圾、不对啦。
public class Main {
    private static final Object object=new Object();
    public static void main(String[] args) throws InterruptedException {
        Thread t1 = new Thread(new Runnable() {
            @Override
            public  void run() {
                synchronized(object){
                    for (int i = 1; i < 75; i+=15) {
                        for (int j = i; j < i + 5; j++) {
                            System.out.println(Thread.currentThread().getName()+" "+j);

                        }
                        object.notifyAll();
                        try {
                            object.wait();
                        } catch (InterruptedException e) {
                            throw new RuntimeException(e);
                        }
                    }
                }
            }
        });

        Thread t2 = new Thread(new Runnable() {
            @Override
            public  void run() {
                synchronized(object){
                    for (int i = 6; i < 75; i+=15) {
                        for (int j = i; j < i + 5; j++) {
                            System.out.println(Thread.currentThread().getName()+" "+j);

                        }
                        object.notifyAll();
                        try {
                            object.wait();
                        } catch (InterruptedException e) {
                            throw new RuntimeException(e);
                        }
                    }
                }
            }
        });

        Thread t3 = new Thread(new Runnable() {
            @Override
            public  void run() {
                synchronized(object){
                    for (int i = 11; i < 75; i+=15) {
                        for (int j = i; j < i + 5; j++) {
                            System.out.println(Thread.currentThread().getName()+" "+j);

                        }
                        object.notifyAll();
                        try {
                            object.wait();
                        } catch (InterruptedException e) {
                            throw new RuntimeException(e);
                        }
                    }
                }
            }
        });

        t1.start();
        Thread.sleep(50);
        t2.start();
        Thread.sleep(50);
        t3.start();
    }
}
